package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.common.base.service.impl.BaseServiceImpl;
import com.example.common.enums.ResponseCodeEnum;
import com.example.common.utils.ApiResult;
import com.example.common.utils.TreeUtil;
import com.example.dao.SuppliesTypeMapper;
import com.example.dao.TAreaMapper;
import com.example.model.entity.SuppliesType;
import com.example.model.entity.TArea;
import com.example.model.vo.AreaTree;
import com.example.service.SuppliesTypeService;
import com.example.service.TAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 *  Service接口实现类
 *
 * @author Tellsea
 * @Description Created on 2020-12-11
 */
@Service
public class TAreaServiceImpl extends BaseServiceImpl<TAreaMapper, TArea> implements TAreaService {

    @Autowired
    private TAreaMapper areaMapper;

    @Override
    public ApiResult<List<AreaTree>> getAreaTree() {
            QueryWrapper<TArea> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().eq(TArea::getIsValid,1L).orderByAsc(TArea::getSortNo);
            List<TArea> sysOrganizationList = areaMapper.selectList(queryWrapper);
            // 3、构建树
            List<AreaTree> orgTrees = TreeUtil.list2Tree(sysOrganizationList);
            return new ApiResult<>(orgTrees);
    }
    @Override
    public  ApiResult<List<TArea>> getList(){
        QueryWrapper<TArea> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(TArea::getIsValid,1L);
        List<TArea> sysOrganizationList = areaMapper.selectList(queryWrapper);
        return new ApiResult<>(sysOrganizationList);
    }
    @Override
    public ApiResult<Boolean> saveT(TArea area){
        area.setCreateDate(LocalDateTime.now());
        areaMapper.insert(area);
        return new ApiResult<>(Boolean.TRUE);
    }
}

